package com.kmxd.ams.app.system;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kmxd.ams.client.system.ISysMessageInfoSvc;
import com.kmxd.ams.client.system.dto.SysMessageInfoAddDTO;
import com.kmxd.ams.client.system.dto.SysMessageInfoEditDTO;
import com.kmxd.ams.client.system.dto.SysMessageInfoQueryDTO;
import com.kmxd.ams.client.system.vo.SysMessageInfoListVO;
import com.kmxd.ams.client.system.vo.SysMessageInfoVO;
import com.kmxd.ams.core.common.query.QueryGen;
import com.kmxd.ams.core.util.IdUtil;
import com.kmxd.ams.infra.system.entity.SysMessageInfo;
import com.kmxd.ams.infra.system.mapper.SysMessageInfoMapper;
import java.util.List;
import java.util.Set;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 消息接收信息表 服务实现类
 *
 * @author nickbi
 * @since 2023-04-11
 */
@Service
@AllArgsConstructor
public class SysMessageInfoSvcImpl extends ServiceImpl<SysMessageInfoMapper, SysMessageInfo>
    implements ISysMessageInfoSvc {

  private SysMessageInfoMapper sysMessageInfoMapper;

  @Override
  public Page<SysMessageInfoListVO> selectPage(Page reqPage, SysMessageInfoQueryDTO req) {
    LambdaQueryWrapper<SysMessageInfo> queryWrapper =
        QueryGen.init(new QueryWrapper<SysMessageInfo>(), req).lambda();
    Page<SysMessageInfo> page = sysMessageInfoMapper.selectPage(reqPage, queryWrapper);
    Page<SysMessageInfoListVO> voPage = BeanUtil.copyProperties(page, Page.class);
    voPage.setRecords(BeanUtil.copyToList(page.getRecords(), SysMessageInfoListVO.class));
    return voPage;
  }

  @Override
  public List<SysMessageInfoListVO> selectList(SysMessageInfoQueryDTO req) {
    LambdaQueryWrapper<SysMessageInfo> queryWrapper =
        QueryGen.init(new QueryWrapper<SysMessageInfo>(), req).lambda();
    List<SysMessageInfo> list = sysMessageInfoMapper.selectList(queryWrapper);
    return BeanUtil.copyToList(list, SysMessageInfoListVO.class);
  }

  @Override
  @Transactional(rollbackFor = Exception.class)
  public void add(SysMessageInfoAddDTO req) {
    SysMessageInfo entity = BeanUtil.copyProperties(req, SysMessageInfo.class);
    sysMessageInfoMapper.insert(entity);
  }

  @Override
  @Transactional(rollbackFor = Exception.class)
  public void edit(SysMessageInfoEditDTO req) {
    SysMessageInfo entity = BeanUtil.copyProperties(req, SysMessageInfo.class);
    sysMessageInfoMapper.updateById(entity);
  }

  @Override
  @Transactional(rollbackFor = Exception.class)
  public void remove(String ids) {
    Set<Long> idList = IdUtil.split(ids);
    this.baseMapper.deleteBatchIds(idList);
  }

  @Override
  public SysMessageInfoVO view(Long id) {
    SysMessageInfo entity = sysMessageInfoMapper.selectById(id);
    return BeanUtil.copyProperties(entity, SysMessageInfoVO.class);
  }
}
